namespace CISLib
{
    using System;
    using System.Runtime.CompilerServices;

    public class MailConfig
    {
        //private string PlainSmtpPass = null;
        public const string SmtpAuthModeKey = "sysmail.smtpauthmode";
        public const string SmtpHostKey = "sysmail.smtphost";
        public const string SmtpPassKey = "sysmail.smtppass";
        public const string SmtpPortKey = "sysmail.smtpport";
        public const string SmtpSenderKey = "sysmail.smtpsender";

        [MethodImpl(MethodImplOptions.Synchronized)]
        public static MailConfig GetInstance()
        {
            return new MailConfig();
        }

        public override string ToString()
        {
            return string.Format("SmtpHost:{0},SmtpPort:{1},SmtpSender:{2},SmtpPass:{3}", new object[] { SmtpHost, SmtpPort, SmtpSender, SmtpPass });
        }

        public static string SmtpAuthMode
        {
            get
            {
                return ManageSystemConfig.GetSystemConfig("sysmail.smtpauthmode");
            }
        }

        public static string SmtpHost
        {
            get
            {
                return ManageSystemConfig.GetSystemConfig("sysmail.smtphost");
            }
        }

        public static string SmtpPass
        {
            get
            {
                string configVar = ManageSystemConfig.GetSystemConfig("sysmail.smtppass");
                if (configVar == "")
                {
                    throw new ApplicationException("SmtpPass Config Not Set.");
                }
                return configVar;
            }
        }

        public static int SmtpPort
        {
            get
            {
                string configVar = ManageSystemConfig.GetSystemConfig("sysmail.smtpport");
                return ((configVar == "") ? 0x19 : int.Parse(configVar));
            }
        }

        public static string SmtpSender
        {
            get
            {
                return ManageSystemConfig.GetSystemConfig("sysmail.smtpsender");
            }
        }
    }
}

